import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.awt.event.InputEvent;
import java.awt.Color;
import static java.lang.Thread.*;

abstract class Ham
{
	private Robot robot;

	private Character ch;
	private boolean running;
	private Area startGame;

	public Ham(Character ch)
	{
		this.ch = ch;
		running = true;
		startGame = new Area(75,379,368,427);
		try
		{
			robot = new Robot();
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}

	public void send(KeyEvent k)
	{
		robot.keyPress(k.getKeyCode());
	}

	public void moveMouse(int x, int y)
	{
		robot.mouseMove(x,y);
	}

	public void moveClick(int x, int y)
	{
		moveMouse(x,y);
		robot.mousePress(InputEvent.BUTTON1_MASK);
	}

	public void moveClick(Area a)
	{
		int x = (int) Math.random() * (a.getX2() - a.getX1()) + a.getX1();
		int y = (int) Math.random() * (a.getY2() - a.getY1()) + a.getY1();
		moveClick(x, y);
	}

	public Coord findPixel(Area area, Color pixelColor)
	{
		Coord coord;
		for (int i = area.getY1(); i <= area.getY2(); i++)
		{
			for (int j = area.getX1(); j <= area.getX2(); j++)
			{
				if ( pixelColor == robot.getPixelColor(i, j) )
				{
					coord = new Coord(i, j);
					return coord;
				}
			}
		}
		coord = new Coord(-1, -1);
		return coord;
	}

	public static void sleep(int ms)
	{
		try
		{
			Thread.sleep((long)ms);
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}

	public static int rand(int min, int max)
	{
    	return min + (int)(Math.random() * (max - min + 1));
	}

	public static void rsleep(int min, int max)
	{
		sleep(rand(min, max));
	}
}